﻿using BookTheBook.Data.Model;
using BookTheBook.Data.NameDefinitions;
using FluentNHibernate.Mapping;

namespace BookTheBook.Data.Mappings
{
    public class BookMap : ClassMap<Book>
    {
        public BookMap()
        {
            Table(TableNames.Book);
            Id(x => x.Id).Column(ColumnNames.BookId);
            Map(x => x.ISBN).Column(ColumnNames.ISBN);
            Map(x => x.Title).Column(ColumnNames.Title);
            Map(x => x.Author).Column(ColumnNames.Author);
            Map(x => x.Publisher).Column(ColumnNames.Publisher);
            Map(x => x.Edition).Column(ColumnNames.Edition);
            Map(x => x.Currency).Column(ColumnNames.Currency);
            Map(x => x.Rating).Column(ColumnNames.Rating);
            Map(x => x.DetailsUrl).Column(ColumnNames.DetailsUrl);
            Map(x => x.Price).Column(ColumnNames.Price);
            Map(x => x.Image).Column(ColumnNames.Image);
            Map(x => x.PublishYear).Column(ColumnNames.PublishDate);
            Map(x => x.Description).Column(ColumnNames.Description);
            HasMany(x => x.Copies).Inverse().Cascade.All().Table(TableNames.Copy).KeyColumn(ColumnNames.BookId);
        }
    }
}
